package com.cz.nongyetongv5.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.cz.nongyetongv5.R;
import com.cz.nongyetongv5.activity.EntDetailActivity;
import com.cz.nongyetongv5.activity.MapViewActivity;
import com.ronri.ams.BaseFragment;


public class EntInfoOperateYzhFragment extends BaseFragment {

    private TextView tv_type;
    private TextView tv_addr;
    private TextView tv_owner;
    private TextView tv_contract;
    private TextView tv_other;
    private TextView tv_scale;
    private TextView tv_transportation;
    private TextView tv_transportation_link;
    private TextView tv_transportation_type;
    private RelativeLayout rl_transportation_link;
    private RelativeLayout rl_transportation_type;
    private View view;
    private ImageView iv_map;

    public static EntInfoOperateYzhFragment newInstance() {
        EntInfoOperateYzhFragment fragment = new EntInfoOperateYzhFragment();
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_ent_info_operate_yzh, null);
        tv_type = view.findViewById(R.id.tv_type);
        tv_addr = view.findViewById(R.id.tv_addr);
        tv_owner = view.findViewById(R.id.tv_owner);
        tv_contract = view.findViewById(R.id.tv_contract);
        tv_other = view.findViewById(R.id.tv_other);
        tv_scale = view.findViewById(R.id.tv_scale);
        tv_transportation = view.findViewById(R.id.tv_transportation);
        tv_transportation_link = view.findViewById(R.id.tv_transportation_link);
        tv_transportation_type = view.findViewById(R.id.tv_transportation_type);
        rl_transportation_link = view.findViewById(R.id.rl_transportation_link);
        rl_transportation_type = view.findViewById(R.id.rl_transportation_type);

        iv_map = view.findViewById(R.id.iv_map);
        iv_map.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (((EntDetailActivity) getActivity()).getEntBean().getLatitude() == null || ((EntDetailActivity) getActivity()).getEntBean().getLatitude() == 0f) {
                    Toast.makeText(getActivity(),"暂无坐标信息",Toast.LENGTH_SHORT).show();
                } else {
                    Intent intent = new Intent(getActivity(), MapViewActivity.class);
                    intent.putExtra("latitude", ((EntDetailActivity) getActivity()).getEntBean().getLatitude());
                    intent.putExtra("longitude", ((EntDetailActivity) getActivity()).getEntBean().getLongitude());
                    startActivity(intent);
                }
            }
        });

        init();
        return view;
    }


    public void init() {
        if (((EntDetailActivity) getActivity()).getEntBean().getCategory_name() != null) {
            tv_type.setText(((EntDetailActivity) getActivity()).getEntBean().getCategory_name());
        }
        if (((EntDetailActivity) getActivity()).getEntBean().getAddress() != null) {
            tv_addr.setText(((EntDetailActivity) getActivity()).getEntBean().getAddress());
        }
        if (((EntDetailActivity) getActivity()).getEntBean().getOwner_amount() != null) {
            tv_owner.setText(((EntDetailActivity) getActivity()).getEntBean().getOwner_amount() +
                    ((EntDetailActivity) getActivity()).getEntBean().getOwner_group_name());
        }
        if (((EntDetailActivity) getActivity()).getEntBean().getContract_amount() != null) {
            tv_contract.setText(((EntDetailActivity) getActivity()).getEntBean().getContract_amount() +
                    ((EntDetailActivity) getActivity()).getEntBean().getContract_group_name());
        }
        if (((EntDetailActivity) getActivity()).getEntBean().getOther_amount() != null) {
            tv_other.setText(((EntDetailActivity) getActivity()).getEntBean().getOther_amount() +
                    ((EntDetailActivity) getActivity()).getEntBean().getOther_group_name());
        }


        if (((EntDetailActivity) getActivity()).getEntBean().getScale_amount() != null) {
            tv_scale.setText(((EntDetailActivity) getActivity()).getEntBean().getScale_amount() +
                    ((EntDetailActivity) getActivity()).getEntBean().getScale_group_name());
        }

        if (((EntDetailActivity) getActivity()).getEntBean().getIs_transportation().equals("0")) {
            tv_transportation.setText("否");
            rl_transportation_link.setVisibility(View.GONE);
            rl_transportation_type.setVisibility(View.GONE);
        } else {
            tv_transportation.setText("是");
            rl_transportation_link.setVisibility(View.VISIBLE);
            rl_transportation_type.setVisibility(View.VISIBLE);
            tv_transportation_link.setText(((EntDetailActivity) getActivity()).getEntBean().getTrans_tache_name());
            tv_transportation_type.setText(((EntDetailActivity) getActivity()).getEntBean().getTrans_category_name());
        }

    }

    //    @OnClick(R.id.iv_map)
    //    public void toMap(ImageView imageView) {
    //        if (((EntDetailActivity) getActivity()).getEntBean().getLatitude() == null || ((EntDetailActivity) getActivity()).getEntBean().getLatitude() == 0f) {
    //            ToastUtils.showToast(getActivity(), "暂无坐标信息");
    //        } else {
    //            Intent intent = new Intent(getActivity(), MapViewActivity.class);
    //            intent.putExtra("latitude", ((EntDetailActivity) getActivity()).getEntBean().getLatitude());
    //            intent.putExtra("longitude", ((EntDetailActivity) getActivity()).getEntBean().getLongitude());
    //            intent.putExtra("addr", ((EntDetailActivity) getActivity()).getEntBean().getAddress());
    //            startActivity(intent);
    //        }
    //    }

}